package it.camelotone.ejb.session;

import it.camelotone.ejb.entity.ServiceBill;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Session Bean implementation class BillingPersistenceService
 */
@Stateless
@LocalBean
public class BillingPersistenceService {
	
	@PersistenceContext(name = "uisproma-ejb")
	private EntityManager entityManager;

    /**
     * Default constructor. 
     */
    public BillingPersistenceService() {
    	
    }
    
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Long addBill(ServiceBill bill) {
    	entityManager.persist(bill);
    	return bill.getId();
    }
    
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void removeBill(Long id) {
    	ServiceBill bill = entityManager.find(ServiceBill.class, id);
    	entityManager.remove(bill);
    }

}
